#!/bin/sh

# if app not exist
if [ ! -f /bin/lld2d ]; then
    exit 0
fi

#wait to start web and run from goahead code
. /etc/scripts/web_wait.sh
web_wait

# get params
. /etc/scripts/global.sh

LOG="logger -t lld2d"

start() {
    get_param
    if [ "$lltdEnabled" = "1" ]; then
	$LOG "Starting LLD2D"
	if [ "$RadioOff" = "1" ]; then
	    lld2d $lan_if
	else
	    lld2d $lan_if ra0
	fi
    fi
}

get_param() {
    eval `nvram_buf_get 2860 lltdEnabled RadioOff`
}

stop() {
  $LOG "Stopping LLD2D"
    killall -q lld2d
    killall -q -SIGKILL lld2d
    rm -rf /var/run/lld2d-* > /dev/null 2>&1
}

case "$1" in
        start)
            start
            ;;

        stop)
            stop
            ;;

        restart)
            stop
            start
            ;;

        *)
            echo $"Usage: $0 {start|stop|restart}"
            exit 1
esac
